# -*- coding: utf-8 -*-
from datetime import timedelta
from jms.ods.lmdm.yl_lmdm_sys_network import jms_ods__yl_lmdm_sys_network
from jms.ods.mysql.sys_manage_region import jms_ods__sys_manage_region
from jms.ods.lmdm.yl_lmdm_sys_network_delivery_r import jms_ods__yl_lmdm_sys_network_delivery_r
from jms.ods.lmdm.yl_lmdm_sys_network_electronic import jms_ods__yl_lmdm_sys_network_electronic
from jms.ods.lmdm.yl_lmdm_sys_network_expand import jms_ods__yl_lmdm_sys_network_expand
from jms.ods.lmdm.yl_lmdm_sys_network_distributi import jms_ods__yl_lmdm_sys_network_distributi
from jms.ods.lmdm.sys_network_area import jms_ods__sys_network_area
from jms.ods.lmdm.sys_agency_area_manager import jms_ods__sys_agency_area_manager
from jms.ods.lmdm.sys_agency_area import jms_ods__sys_agency_area
from jms.dim.dim_sys_area_info import jms_dim__dim_sys_area_info
from jms.dim.dim_sys_area_info_jt import jms_dim__dim_sys_area_info_jt
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

jms_dim__dim_network_whole_massage = SparkSqlOperator(
    task_id='jms_dim__dim_network_whole_massage',
    task_concurrency=1,
    email=['shenjiaming@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    pool_slots=5,
    master='yarn',
    name='jms_dim__dim_network_whole_massage_{{ execution_date | cst_ds_nodash }}',
    sql='jms/dim/dim_network_whole_massage/execute.hql',
    executor_cores=3,
    executor_memory='6G',
    num_executors=4,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          #'spark.dynamicAllocation.maxExecutors': 20,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.maxExecutors': 11,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '1G',  # 堆外内存
          'spark.sql.shuffle.partitions': 200,
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 20,  # 每天生成 20 个分区
              'hive.exec.max.dynamic.partitions.pernode': 20,  # 每天生成 20 个分区
              },
    yarn_queue='pro',
    execution_timeout=timedelta(minutes=30),
)

jms_dim__dim_network_whole_massage << [
    jms_ods__yl_lmdm_sys_network,
    jms_ods__sys_manage_region,
    jms_ods__yl_lmdm_sys_network_delivery_r,
    jms_ods__yl_lmdm_sys_network_electronic,
    jms_ods__yl_lmdm_sys_network_expand,
    jms_ods__yl_lmdm_sys_network_distributi,
    jms_ods__sys_network_area,
    jms_ods__sys_agency_area_manager,
    jms_ods__sys_agency_area,
    jms_dim__dim_sys_area_info,
    jms_dim__dim_sys_area_info_jt
]
